home *** CD-ROM | disk | FTP | other *** search
- /*
- dshell v3
-
- フォントファイル関連
- */
-
- #include "dsh.h"
-
-
- /*
- フォントファイル名の解釈と対応するフォント番号の取得
- */
- int
- getFontNo(uchar *p, uchar *cutPath, struct NAMECKBUF *fname, uchar termChr)
- {
- uchar pflag = FALSE;
- uchar c, cbak, *q = p;
- int n, firstSect = 0;
-
- while ((c = *q++) > ' ' && c != termChr)
- ;
- q--;
- cbak = *q;
- *q = '\0';
- while (c = *p++) {
- if (c == '+') // ドキュメントファイルと同一パスから探す
- pflag = TRUE;
- else
- break;
- }
- if (c == '\0' || NAMECK(--p, fname) != 0) {
- *q = cbak;
- return -1;
- }
- if (pflag) {
- char temp[256];
- strcpy(temp, cutPath);
- strcat(temp, p);
- NAMECK(temp, fname);
- }
- *q = cbak;
- strcat((char *)fname, fname->name);
- for (q = (uchar *)fname; *q++ != '\0';)
- ;
- q -= 3;
- if (q >= (uchar *)fname && isdigit(*q) && isdigit(*(q + 1))) {
- firstSect = atoi(q);
- if (firstSect < 1 || firstSect > 94)
- firstSect = 0;
- }
- strcat((char *)fname, fname->ext);
- dstrupr((char *)fname);
-
- for (n = 0; n < FONTMAX; n++) {
- if (font16[n].fname == NULL) {
- FILE *fp;
- int fsize;
-
- font16[n].size = 0;
- font16[n].fname = (char *)fname;
- if ((fp = fopen((char *)fname, "rb")) != NULL) {
- fsize = dfilelength(fileno(fp));
- if (fsize == 2048 || fsize == 4096) {
- font16[n].size++;
- font16[n].sect = 0;
- } else if (fsize <= 32*94*94 && (fsize % (32*94)) == 0) {
- int nSect = fsize / (32*94);
- font16[n].size = nSect;
- if (firstSect > 0 && firstSect + nSect <= 94)
- font16[n].sect = firstSect;
- else if (nSect <= 2)
- font16[n].sect = 4; // かな
- else if (nSect == 32)
- font16[n].sect = 16; // 第1水準漢字
- else if (nSect == 47)
- font16[n].sect = 48; // 第2水準漢字
- else
- font16[n].sect = 1;
- }
- fclose(fp);
- }
- font16[n].fname = NULL;
- return n;
- } else if (strEqu(font16[n].fname, (char *)fname)) {
- return n;
- }
- }
-
- dabort("フォントファイル数が最大値を越えます");
- return -1;
- }
-
-
- /*
- フォントファイルを読み込む
-
- fontNo: フォントファイル管理情報の格納開始番号
- */
- int
- readFontFile(int fontNo)
- {
- FILE *fp;
- int fsize;
- int first, last;
- char temp[100];
- void *p;
-
- first = fontNo;
- for (last = fontNo; last < FONTMAX && font16[last].fname != NULL; last++)
- ;
- for (; fontNo < CUT_MAX && font16[fontNo].fname != NULL; fontNo++) {
- w_mes(0, "フォントファイルをロード中です");
- w_mes(1, font16[fontNo].fname);
- w_mes(2, "しばらくお待ち下さい");
- sprintf(temp, "%3d / %3d", fontNo - first + 1, last - first);
- w_mes(3, temp);
-
- font16[fontNo].pat = NULL;
- if (font16[fontNo].size == 0) {
- SIZE_ERROR:
- w_open();
- sprintf(temp, "%s: ファイルサイズが不当です", font16[fontNo].fname);
- ERROR:
- w_mes(0, temp);
- w_mes(2, "処理を続けます");
- w_wait(100);
- continue;
- }
- if ((fp = fopen(font16[fontNo].fname, "rb")) == NULL) {
- w_open();
- sprintf(temp, "%sがオープンできません", font16[fontNo].fname);
- goto ERROR;
- }
-
- fsize = dfilelength(fileno(fp));
- if (font16[fontNo].sect == 0) {
- if (fsize != 2048 && fsize != 4096) {
- fclose(fp);
- goto SIZE_ERROR;
- }
- p = (void *)MALLOC(4096);
- if ((int)p < 0) {
- NOMEM:
- fclose(fp);
- w_open();
- strcpy(temp, "メモリ不足です");
- goto ERROR;
- }
- if (fread(p, sizeof(char), fsize, fp) != fsize) {
- READ_ERROR:
- fclose(fp);
- MFREE(p);
- w_open();
- sprintf(temp, "%sが読み込めません", font16[fontNo].fname);
- goto ERROR;
- }
- #if 0
- if (fsize == 2048)
- memcpy(p + 2048, defFont16.table[0] + 2048, 2048); // 半角カナ
- #endif
- } else {
- if (fsize != font16[fontNo].size * 32 * 94) {
- fclose(fp);
- goto SIZE_ERROR;
- }
- p = (void *)MALLOC(fsize);
- if ((int)p < 0)
- goto NOMEM;
- if (fread(p, sizeof(char), fsize, fp) != fsize)
- goto READ_ERROR;
- }
- font16[fontNo].pat = p;
- fclose(fp);
- }
-
- return fontNo;
- }
-